﻿using Core;
using FairyGUI;

public class FGUIWidget<T>: IFGUIWidget<T> where T : GObject
{
    protected T m_root;

    public bool IsDisposed { get; protected set; }

    void IFGUIWidget<T>.Initialize(T root, params object[] args)
    {
        this.m_root = root;
        OnInitialize(args);
    }

    public void Show()
    {
        if(m_root.parent == null)
        {
            GRoot.inst.AddChild(m_root);
        }
        else
        {
            m_root.visible = true;
        }
        OnShow();
    }

    public void Hide()
    {
        if(m_root.parent == GRoot.inst)
        {
            GRoot.inst.RemoveChild(m_root);
        }
        else
        {
            m_root.visible = false;
        }
        OnHide();
    }

    public void Dispose()
    {
        m_root?.Dispose();
    }

    protected virtual void OnInitialize(params object[] args)
    {

    }

    protected virtual void OnShow()
    {

    }
    protected virtual void OnHide()
    {

    }

    

}
